package org.jsbd.boss.task;

import java.util.Set;

import org.jsbd.boss.common.redis.RedisClient;
import org.jsbd.boss.util.CacheKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.zhexinit.proxy.domain.HttpProxyLog;

import edu.hziee.common.queue.DelayExecuteBuffer;

/**
 * mark和设备数定时刷新
 * 
 * @author zbh
 * 
 */
public class InitMarkTask implements Runnable {

	@Autowired
	private RedisClient redisClient;

	public static final Logger LOGGER = LoggerFactory.getLogger(InitMarkTask.class);

	public static final int DEVISESET_EXPIRY_TIME = 30 * 60 * 1000; // 缓存失效时间为30分钟

	private  static Set<String> devicelist;

	@Autowired
	private DelayExecuteBuffer<HttpProxyLog> zxHttpProxyLogBuffer;

	public void start() {
		Thread t = new Thread(this);
		t.start();
	}

	@Override
	public void run() {
		while (true) {
			try {
				
				long now = System.currentTimeMillis();
				long starttime = System.currentTimeMillis() - DEVISESET_EXPIRY_TIME;
				devicelist = redisClient.rangeByScore(CacheKey.DEVICELIST_ZSET_KEY, starttime, now);

			} catch (Exception e) {
				LOGGER.error("Any error msg that u want to write", e);
			} finally {
				try {
					Thread.sleep(1000 * 60);
				} catch (InterruptedException e) {
					LOGGER.error("Any error msg that u want to write", e);
				}
			}
		}

	}

	public static Set<String> getDevicelist() {
		return devicelist;
	}

	public static void setDevicelist(Set<String> devicelist) {
		InitMarkTask.devicelist = devicelist;
	}
	
	

}
